/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.feiyue.basic.reader.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

import com.feiyue.basic.reader.pojo.FileInfo;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class FileInfoDao extends Dao {
	private static final String COMPERE = "file_info";

	public FileInfoDao(Context paramContext) {
		super(paramContext);
		this.db.setTableName("file_info");
	}

	private List<FileInfo> getList(Cursor paramCursor) {
		ArrayList localArrayList = new ArrayList();
		if (paramCursor != null)
			paramCursor.moveToFirst();
		while (true) {
			if (paramCursor.isAfterLast()) {
				paramCursor.close();
				return localArrayList;
			}
			FileInfo localFileInfo = new FileInfo();
			localFileInfo.setId(paramCursor.getLong(0));
			localFileInfo.setName(paramCursor.getString(1));
			localFileInfo.setIcon(paramCursor.getInt(2));
			localFileInfo.setSize(paramCursor.getLong(3));
			localFileInfo.setType(paramCursor.getString(4));
			localFileInfo.setPath(paramCursor.getString(5));
			localFileInfo.setNid(paramCursor.getString(6));
			localFileInfo.setPid(Integer.valueOf(paramCursor.getInt(7)));
			localArrayList.add(localFileInfo);
			paramCursor.moveToNext();
		}
	}

	public void delete(long paramLong) {
		this.db.delete(paramLong);
	}

	public String getApi(String paramString, long paramLong) {
		return paramString + "_" + paramLong;
	}

	public List<FileInfo> getList() {
		return getList(this.db.query(new String[] { "id", "name", "icon",
				"size", "type", "path", "nid", "pid" }, null, null, null, null,
				null));
	}

	public List<FileInfo> getList(Integer paramInteger) {
		DBHelper localDBHelper = this.db;
		String[] arrayOfString1 = { "id", "name", "icon", "size", "type",
				"path", "nid", "pid" };
		String[] arrayOfString2 = new String[1];
		arrayOfString2[0] = String.valueOf(paramInteger);
		return getList(localDBHelper.query(arrayOfString1, "pid = ?",
				arrayOfString2, null, null, null));
	}

	public List<FileInfo> getList(String paramString) {
		return getList(this.db.query(new String[] { "id", "name", "icon",
				"size", "type", "path", "nid", "pid" }, "path = ?",
				new String[] { paramString }, null, null, null));
	}

	public Integer save(FileInfo paramFileInfo) {
		List localList = getList(paramFileInfo.getPath());
		ContentValues localContentValues = new ContentValues();
		localContentValues.put("name", paramFileInfo.getName());
		localContentValues
				.put("icon", Integer.valueOf(paramFileInfo.getIcon()));
		localContentValues.put("size", Long.valueOf(paramFileInfo.getSize()));
		localContentValues.put("type", paramFileInfo.getType());
		localContentValues.put("path", paramFileInfo.getPath());
		localContentValues.put("nid", paramFileInfo.getNid());
		localContentValues.put("pid", paramFileInfo.getPid());
		long l;
		if (localList.size() == 0) {
			l = this.db.insert(localContentValues);
		} else {
			l = ((FileInfo) localList.get(0)).getId();
			this.db.update(paramFileInfo.getId(), localContentValues);
		}
		
		return Integer.valueOf((int) l);
	}

	public void save(List<FileInfo> paramList) {
		Iterator localIterator = paramList.iterator();
		while (true) {
			if (!(localIterator.hasNext()))
				return;
			save((FileInfo) localIterator.next());
		}
	}
}